package cn.dengta.webapp.im.entity;

import java.util.Date;

import cn.dengta.webapp.base.entity.TimeBasedEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.codeplayer.util.Cmp;
import me.codeplayer.util.X;

/**
 * 搭讪退回日统计
 *
 * @author lgy
 * @since 2022-12-22
 */
@Setter
@Getter
@Accessors(chain = true)
@TableName("im_greet_back_daily")
public class GreetBackDaily extends TimeBasedEntity {

	public static final String GREET_BACK_DAILY_LOCK = "greet_back_daily_lock";
	/** 用户ID */
	Long userId;
	/** 搭讪退回总数 */
	Integer greetBackCount;
	/** 消息退回总数 */
	Integer msgBackCount;
	/** 统计日期 */
	Date reportTime;
	/** 目标ID */
	Long assocId;

	public GreetBackDaily init(GreetBackDaily input, Date now) {
		this.userId = X.expectNotNull(userId, input.userId);
		this.greetBackCount = X.expectNotNull(input.greetBackCount, greetBackCount);
		this.msgBackCount = X.expectNotNull(input.msgBackCount, msgBackCount);
		this.reportTime = X.expectNotNull(input.reportTime, reportTime);
		super.initTime(now);
		return this;
	}

	public GreetBackDaily init(Long userId, Date reportTime) {
		this.userId = userId;
		this.greetBackCount = 0;
		this.msgBackCount = 0;
		this.reportTime = reportTime;
		return this;
	}

	public GreetBackDaily add(GreetBackDaily input) {
		if (input != null) {
			if (Cmp.nullToZero(input.greetBackCount) > 0) {
				this.greetBackCount += input.greetBackCount;
			}
			if (Cmp.nullToZero(input.msgBackCount) > 0) {
				this.msgBackCount += input.msgBackCount;
			}
		}
		return this;
	}

	public static final String USER_ID = "user_id";
	public static final String ASSOC_ID = "assoc_id";
	public static final String GREET_BACK_COUNT = "greet_back_count";
	public static final String MSG_BACK_COUNT = "msg_back_count";
	public static final String REPORT_TIME = "report_time";

}
